package top.houry.im.client.handler.impl;

import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.houry.im.client.event.ImClientUiLoginEvent;
import top.houry.im.client.handler.ImClientMsgTypeHandler;
import top.houry.im.client.listener.ImClientNettyProcessorListener;
import top.houry.im.client.proto.ImMessage;

import java.util.concurrent.TimeUnit;

public class ImClientHeartBeatHandlerImpl implements ImClientMsgTypeHandler {
    private static final Logger log = LoggerFactory.getLogger(ImClientHeartBeatHandlerImpl.class);
    @Override
    public void processImMsg(ImMessage.Client client, ChannelHandlerContext ctx) {

    }


    public void sendHeartBeatMsg(ChannelHandlerContext ctx) {
        ImMessage.Client.Builder client = ImMessage.Client.newBuilder();
        ImMessage.HeartBeatReqMessage.Builder req = ImMessage.HeartBeatReqMessage.newBuilder();
        client.setMsgType("client.heartbeat.req");
        client.setBytesData(req.build().toByteString());
        ctx.channel().eventLoop().scheduleAtFixedRate(() -> ctx.writeAndFlush(client).addListener(new ImClientNettyProcessorListener("客户端上送心跳")), 0, 5, TimeUnit.SECONDS);
    }

}
